<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>公益动态管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>多功能搜索</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" id="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" id="shousuobtn" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 发布公告</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">

            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>

            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="Exhibition">展示</a>


            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="NoExhibition">不展示</a>

        </script>

    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>

    var hostport = document.location.host
    var hostf = document.location.protocol
    var url = hostf + "//" + hostport
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: url + '/getPictureAll',
            toolbar: '#toolbarDemo',
            method: 'post',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[

                {type: "radio", width: 50},
                {field: 'pictureId', width: 200, title: 'ID', sort: true},
                {field: 'pictureOfficialAccountUrl', width: 200, title: '公众号链接'},
                {field: 'pictureDetails', width: 200, title: '标题名称', sort: true},
                {field: 'pictureState', width: 200, title: '状态', sort: true},
                {title: '操作', minWidth: 50, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 50],
            limit: 10,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            var tit = $("#title").val();
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    title: tit
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '发布图片',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/news-add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                /* var checkStatus = table.checkStatus('currentTableId')
                      data = checkStatus.data;
                 layer.alert(JSON.stringify(data));*/
                alert(111111)
            } else if (obj.event === 'Exhibition') {
                alert(111)
            }
        });

        //监听表格单选框选择
        table.on('radio(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data.id)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;

            if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    var data = obj.data;
                    console.log(data.pictureName);
                    obj.del();
                    layer.close(index);
                    $.ajax({
                        type: "post",
                        url: url + "/deletePicture",
                        dataType: "json",
                        data: {"pictureName": data.pictureName},
                        success: function (result) {
                            if (result.code == 0) {
                                layer.alert('删除公告成功！', {icon: 1});
                                alert(serverPath)
                            }
                            console.info(result);
                        },
                        error: function () {
                            console.log("网络出错！请重新连接")
                        }
                    });


                });
            } else if (obj.event === 'Exhibition') {
                if (obj.event === 'Exhibition') {
                    layer.confirm('是否设置成展示', function (index) {
                        var data = obj.data;
                        console.log(data.pictureName);
                        obj.del();
                        layer.close(index);

                        $.ajax({
                            type: "post",
                            url: url + "/setExhibition",
                            dataType: "json",
                            data: {"pictureName": data.pictureName},
                            success: function (result) {
                                if (result.code == 0) {
                                    layer.alert('设置成展示成功！', {icon: 1});
                                    setTimeout(function(){location.reload()},100);
                                } else {
                                    layer.alert("设置成展示失败,请确认是否含有两张展示的图片", {icon: 2})
                                }
                                console.info(result);
                            },
                            error: function () {
                                console.log("网络出错!")
                            }
                        });


                    });
                }
            } else if (obj.event === "NoExhibition") {
                layer.confirm('是否设置成不展示', function (index) {
                    var data = obj.data;
                    console.log(data.pictureName);
                    obj.del();
                    layer.close(index);

                    $.ajax({
                        type: "post",
                        url: url + "/getExhibition",
                        dataType: "json",
                        data: {"pictureName": data.pictureName},
                        success: function (result) {
                            if (result.code == 0) {
                                layer.alert('设置成不展示成功！', {icon: 1});
                                setTimeout(function(){location.reload()},100);
                            } else {
                                layer.alert("设置成不展示失败", {icon: 2})
                            }
                            console.info(result);
                        },
                        error: function () {
                            console.log("网络出错!")
                        }
                    });


                });

            }
        });
        /*  table.on('tool(currentTableFilter)', function (obj) {
              var data = obj.data;
              if (obj.event === 'Exhibition') {
                  layer.confirm('是否设置成展示', function (index) {
                      var data = obj.data;
                      console.log(data.pictureName);
                      obj.del();
                      layer.close(index);

                      $.ajax({
                          type: "post",
                          url: "http://192.168.0.108:8081/setExhibition",
                          dataType: "json",
                          data: {"pictureName": data.pictureName},
                          success: function (result) {
                              if (result.code == 0) {
                                  layer.alert('设置成展示成功！', {icon: 1});
                              }else {
                                  layer.alert("设置成展示失败,请确认是否含有两张展示的图片", {icon: 2})
                              }
                              console.info(result);
                          },
                          error: function () {
                              console.log("网络出错!")
                          }
                      });


                  });
              }
          });*/

    });
</script>

</body>
</html>

<!-- <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
    <script src="../js/jquery.table2excel.js"></script>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" id="upload" role="form">
    <input type="file" name="file">
    输入图片名称<input type="text" name="filename" >
    输入图片绑定的url<input type="text" name="pictureTestUrl" >
    输入图片上传人<input type="text" name="pictureUser" >
    输入图片详情<input type="text" name="pictureDetails" >
    <input type="button" id="but_button" value="上传">



</form>

<script type="text/javascript">

    $("#but_button").click(function () {
        var data = new FormData($("#upload")[0]);
        var data2 = new FormData($("#upload")[1]);
        var data3 = new FormData($("#upload")[2]);
        var data4 = new FormData($("#upload")[3]);

        console.log(data);
        $.ajax({
            "url": "http://192.168.0.108:8081/submit",
            "data": data,data2,data3,data4,
            "type": "POST",
            "processData": false,
            "contentType": false,
            "dataType": "json",
            "success": function (json) {
                if (json.state == 200) {
                    alert("上传成功")
                } else {
                    alert(json.message)
                }
            },
            "error": function () {
                alert("上传出错")
            }
        })
    })
</script>
</body>
</html> -->